<template>
	<view>
		<u-navbar
		:autoBack="true"
		:border="true"
		fixed
		>
		<view  slot="center" class="search">
			<u-search 
			placeholder="请输入手机号/邮箱/钉钉号搜索" 
			shape="square" 
			:showAction="false" 
			@search="getUser(phone)"
			v-model="phone">
			</u-search>
		</view>
		</u-navbar>
		<view class="is-hide" v-show="isHide(phone)" @click="getUser(phone)">
			<view class="icon-i">
				<uni-icons size="26" type="personadd-filled" color="white"></uni-icons>
			</view>
			<text>网络查找手机/邮箱/钉钉号:</text>
			<text style="color: #0080ff;">{{value}}</text>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				toast:{
					type: 'default',
					title: '默认主题',
					message: "无法找到该用户",
				},
				value:'',
				phone:'',
			}
		},
		methods: {
			getUser(phone){
				let _this = this;
				uni.request({
					url:"http://localhost:8090/nailCampus/user/searchByPhone/"+this.phone,
					method:'GET', 
					success(res) {
						console.log(res.data)
						if(res.data.code === 200){
							uni.navigateTo({
								url:'/pages/book/addNewFriend/user-info?id='+res.data.data.id
							})
						}else{
							_this.showToast(_this.toast)
						}
					}
				})
			},
			showToast(params) {
				this.$refs.uToast.show({
					...params,
				})
			},
			isHide(phone){
				if(phone.length === 0){
					return false;
				}
				if(phone.length < 12){
					this.value = phone;
					return true;
				}
				if(phone.length === 12){
					this.value = phone.slice(0,10)+'...';
					return true;
				}
				return true;
			}
		}
	}
</script>

<style lang="less" scoped>
	.search{
		width: 80%;
	}
	.is-hide{
		padding: 3%;
		margin-top: 12%;
		display: flex;
		border-bottom: 1rpx solid #c2c2c2;
		.icon-i{
			padding: 1%;
			background-color: #0080ff;
			border-radius: 15rpx;
			border: none;
		}
		text{
			margin-left: 3%;
			margin-top: 1%;
		}
	}

</style>
